
{% macro field(row, lname, label) %}
    <tr>
        <td class="label">
            <label id="l{{ lname }}" for="{{ lname }}">{{ label }}:</label>
        </td>
        <td class="field">
            {{ form_widget(row) }}
        </td>
        <td class="status"></td>
        <td>
            {{ form_errors(row) }}
        </td>
    </tr>
{% endmacro %}

{% block content %}

<tr>
    <td class="content">
        <div class="wrapper">
                <h1 class="ml">Создание нового домена:</h1>
        </div>
        <div id="add_box">
          <div id="add_wrap">
            <form id="domain_form" method="post" order="{{ order_name }}" action="">
                <table>
                   {{ _self.field(form.name, 'name', 'домен') }}
                   {{ _self.field(form.first_ns_server, 'first_ns_server', 'первый ns сервер') }}
                   {{ _self.field(form.second_ns_server, 'second_ns_server', 'второй ns сервер') }} 
                   {{ form_widget(form._token) }}
                   <tr>
                        <td align="right">
                            шаблон:
                        </td>
                        <td>
                            <select name="template">
                                {% for key, template in templates %}
                                <option value="{{ key }}">{{ template }}</option>
                                {% endfor %}
                            </select>
                        </td>
                        <td>
                            <a href="" id="show_template">параметры</a>
                        </td>
                        <td></td>
                   </tr>
                   <tr>
                        <td></td>
                        <td></td>
                        <td>
                            <div id="template_content" style="display:none"></div>
                        </td>
                        <td></td>
                   </tr>
                <tr>
                    <td>
                    <div class="field">
                        <input name="add_domain" type="submit" order="{{ order_name }}" value="Создать"/>
                    </div>
                    </td>
                </tr>
                </table>
            </form>
           </div>
        </div>
        <div class="end"></div>
        <script type="text/javascript">
        var validator = $('#domain_form[order="{{ order_name }}"]').validate({
		rules: {
			'domains[name]': {
				required: true,
				check_new_domain: true
			}
		},
		messages: {
			'domains[name]': {
				required: "Введите домен"
			}
		},

		submitHandler: function(form) {
			form.submit();
		},
 
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		},
		
		onkeyup: false
	});
	
	$.validator.addMethod("check_new_domain", function(value, element) 
	{
		var check_new_domain = $.ajax({ type: "GET", url: "./shared_check_new_domain/"+value, async: false }).responseText;
		if (check_new_domain != "true")
		{
			$.validator.messages.check_new_domain = check_new_domain;
			return false;
		}
		else
			return true;
	}
	);
        </script>
    </td>
</tr>

{% endblock %}